/*******************************************************************************
 * Copyright (c) 2011 Olexandr V. Shaposhnikov.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Olexandr V. Shaposhnikov - initial API and implementation and/or initial documentation
 *******************************************************************************/
package com.funkyroach.use.core.search;

import org.eclipse.dltk.ast.ASTNode;
import org.eclipse.dltk.internal.core.search.matching.FieldLocator;
import org.eclipse.dltk.internal.core.search.matching.FieldPattern;
import org.eclipse.dltk.internal.core.search.matching.MatchingNodeSet;

import com.funkyroach.use.core.ast.USArgument;
import com.funkyroach.use.core.ast.USVariableDeclaration;

public class USFieldLocator extends FieldLocator {

	public USFieldLocator(FieldPattern pattern) {
		super(pattern);
	}

	public int match(ASTNode node, MatchingNodeSet nodeSet) {
		if (node instanceof USVariableDeclaration) {
			USVariableDeclaration usVarDecl = (USVariableDeclaration) node;
			String name = new String(this.pattern.getIndexKey());
			if (usVarDecl.getName().equals(name)) {
				return nodeSet.addMatch(node, ACCURATE_MATCH);
			}
		} else if (node instanceof USArgument) {
			USArgument usArg = (USArgument) node;
			String name = new String(this.pattern.getIndexKey());
			if (usArg.getName().equals(name)) {
				return nodeSet.addMatch(node, ACCURATE_MATCH);
			}
		}
		return IMPOSSIBLE_MATCH;
	}
}
